﻿import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from Entities import *
from entities import *
def Add(TenLoaiHinh):
    loaihinh = LoaiHinhCongViec(TenLoaiHinh = TenLoaiHinh)
    loaihinh.put()
    
def Get(keyNguoiDung, LoaiHinhID=0):
    try:
        nguoidung = NguoiDung.get(db.Key(keyNguoiDung)) 
    except:
        return "Invalid Key"
    loaihinh_list = []
    if LoaiHinhID > 0:
        try:
            loaihinhs = LoaiHinhCongViec.get_by_id(LoaiHinhID)
        except:
            return "Invalid LoaiHinhID"
        loaihinh_dict ={}
        loaihinh_dict['LoaiHinhID'] = LoaiHinhID
        loaihinh_dict['TenLoaiHinh'] = loaihinhs.TenLoaiHinh
        loaihinh_list.append(loaihinh_dict)
    else:
        loaihinhs = LoaiHinhCongViec.all()
        for loaihinh in loaihinhs:
            loaihinh_dict ={}
            loaihinh_dict['LoaiHinhID'] = loaihinh.key().id()
            loaihinh_dict['TenLoaiHinh'] = loaihinh.TenLoaiHinh
            loaihinh_list.append(loaihinh_dict)
    tuple_loaihinh = tuple(loaihinh_list)  
    return tuple_loaihinh